package logic

import (
	"context"
	"mall/mallrpc/mallrpc"

	"mall/api/internal/svc"
	"mall/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserAddLogic {
	return &UserAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserAddLogic) UserAdd(req *types.UserAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.MallRpc.UserAdd(l.ctx, &mallrpc.UserAddRequest{
		Name:   req.Name,
		Title:  req.Title,
		Area:   req.Area,
		Price:  float32(req.Price),
		Img:    req.Img,
		Num:    req.Num,
		Userid: req.UserId,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    "500",
			Data:    nil,
		}, nil
	}

	return &types.Response{
		Message: "添加成功",
		Code:    "200",
		Data:    add,
	}, nil
}
